<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<%@ include file="../../../web/header.jsp" %>

<title>课程信息维护</title>
</head>

<body>
<div class="layui-collapse">
	<div class="layui-colla-item">
		<h2 class="layui-colla-title">课程信息查询</h2>
	
	<div class="layui-colla-content layui-show">
		<fieldset class="layui-elem-field layui-field-title"  >
	<legend>课程信息信息</legend>
      <form class="layui-form">
      	<div class="layui-form-item">
      	 	<label class="layui-form-label">课程编号</label>
      	    <div class="layui-input-inline">
      	    	<input type="text" class="layui-input" name="courseId" placeholder="请输入课程编号"></input>
      	    
      	    </div>
      	    <label class="layui-form-label">课程名称</label>
      	    <div class="layui-input-inline">
      	    	<input type="text" class="layui-input" name="courseName" placeholder="请输入课程名称"></input>
      	    
      	    </div>
      	  <label class="layui-form-label"></label>
      	    
      	   <span>
      	    	<input  type="button" class="layui-btn" lay-submit lay-filter="select"  name="action" value="查 询" style="width:80px" id="select"></input> 	   
      	    	<button type="reset" class="layui-btn" value="重置" style="width:80px">重置</button>
      	    	<input type="javascript:;"  type="btn" class="layui-btn" onclick="add()" value="添加" style="width:80px" ></input>
      	    
      	    </span>
    	         	
      	</div>	
      	
      	<div >
<!--       	   <input type="hidden" name="action" value="page"/> -->
      	   <input type="hidden" name="pageIndex" value="1"/>
      	   <input type="hidden" name="pageLimit" value="10"/>
      	
      	</div>
      </from>
      	
	</fieldset>
	</div>
	</div>
	
</div>

<div class="layui-form" >
	<table class="layui-table">
		<colgroup>
		   <col width="%10"><col width="15%"><col width="15%">
		   <col width="%10"><col width="15%"><col width="15%">
		</colgroup>
		<thead>
			<tr>
			 	<th>序号</th><th>课程编号</th><th>课程名称</th>
			 	<th>上课时间</th><th>学分</th><th>任课教师工号</th>
			 	<th>操作</th>
			 	
			</tr>
		</thead>
		<tbody id="course_tbody">
		
		</tbody>
	</table>
	<div id="pageInfoUser" style="text-align:right;padding-right:30px"></div>

</div>

</body>

<script src="../../static/js/base.js"></script>
<script type="text/javascript">
element.render();
refresh();

formSubmit("/StudentMangers/CourseServlet","submit(select)","json",function select(data){
	 
	 
     var datas = JSON.stringify(data);
     datas = eval("("+datas+")");
    
	var curr = $("input[name='pageIndex']").val();
	var limit = $("input[name='pageLimit']").val();
	
	

	
	setPageInfo("pageInfoUser",datas.count,curr,limit,function(obj,first){  //first 判断是否为首次
		
		var curr = $("input[name='pageIndex']").val(obj.curr);
		var limit = $("input[name='pageLimit']").val(obj.limit);
		
		//首次不执行
	    if(!first){
	      refresh();
	    }
	});  //分页
	
	
	
	var html="";
	
	$.each(datas.list,function(i,dom){
		i++;
		var id = dom.courseId;
		var name = dom.courseName?dom.courseName:"";
		var time= dom.time?dom.time:"";
		var gradePoint = dom.gradePoint?dom.gradePoint:"";
		var teacherId = dom.teacherId?dom.teacherId:"";
		var d={i:i,id:id,name:name,time:time,gradePoint:gradePoint,teacherId:teacherId};
	    var  laytpl = layui.laytpl;
		
		 html +=  laytpl($("#tradd").html()).render(d);
		
		
		  
	})
	$("#course_tbody").html(html);

	
})

refresh();

function refresh(){
	$("#select").click();
}

function dele(i,id){
	
	if(confirm("确定要删除吗？")){
					
		
		ajax("/StudentMangers/CourseServlet",{action:"删除",courseId:id},"text",function(data){
			
			
			if(data=="1"){			
			
				$("#tr"+i).remove();
				
				
				layer.msg("删除成功");
					refresh();
			}
			
		})
				
	}

}


function add(){
	
	
	layer.open({
		type:2,
		area:['750px','500px'],
		fixed:false,
		maxmin:true,
		content: "./add.jsp",
        end:refresh,
	})
	

}

function update(i,id,name,gradePoint,time,teacherId){
	layer.open({
		type:2,
		area:['800px','500px'],
		fixed:false,
		maxmin:true,
		content: "./update.jsp?i="+i+"&id="+id+"&name="+name+"&gradePoint="+gradePoint+"&time="+time+"&teacherId="+teacherId,
        end:refresh,
	})
	
}



</script>

<script type="text/html" id="tradd">
<tr id="tr"+{{d.i}}}>
  <td>{{d.i}}</td>
  <td>{{d.id}}</td>
  <td>{{d.name}}</td>
  <td>{{d.time}}</td>
  <td>{{d.gradePoint}}</td>
  <td>{{d.teacherId}}</td>
   <td>
  <a href="javascript:;"class="layui-btn layui-btn-danger" lay-submit lay-filter="delete" name="action" onclick="dele({{d.i}},{{d.id}})" value="删除">
<i class= "layui-icon layui-icon-delete" ></i>
</a>&nbsp&nbsp
  <a href="javascript:;"  class="layui-btn"  lay-submit lay-filter="update" name="action" onclick="update({{d.i}},{{d.id}},'{{d.name}}','{{d.gradePoint}}','{{d.time}}','{{d.teacherId}}')">修改</a>

  </td>
</tr>
</script>
</html>
